//
//  CustomTableViewCell.m
//  通讯录 _自定义cell
//
//  Created by 洛洛大人 on 16/6/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CustomTableViewCell.h"
#import "Model.h"
#import "Contact.h"
#define kwidth self.contentView.frame.size.width
#define kHeight self.contentView.frame.size.height
@interface CustomTableViewCell()
@property(nonatomic, retain)UIImageView *addressBookImageView;
@property(nonatomic, retain)UILabel *nameLabel;
@property(nonatomic, retain)UILabel *numberLabel;

@end

@implementation CustomTableViewCell

-(void)dealloc{
    [_addressBookImageView release];
    [_nameLabel release];
    [_numberLabel release];
    [_cellModel release];
    [super dealloc];
    
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.addressBookImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_addressBookImageView];
        [_addressBookImageView release];
        
        self.nameLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_nameLabel];
        [_nameLabel release];
        
        self.numberLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_numberLabel];
        [_numberLabel release];
        
        
    
    
    }
    return self;
    
}

-(void)layoutSubviews {
    [super layoutSubviews];
    
    self.addressBookImageView.frame = CGRectMake(10, 10, kwidth * 0.3, kHeight - 20);
    self.addressBookImageView.backgroundColor = [UIColor orangeColor];
    
    self.nameLabel.frame = CGRectMake(_addressBookImageView.frame.size.width + 40, 20, kwidth * 0.5, kHeight * 0.3);
    self.nameLabel.backgroundColor = [UIColor greenColor];
    
    self.numberLabel.frame = CGRectMake(_nameLabel.frame.origin.x, kHeight * 0.2 + 40, kwidth * 0.5,  kHeight * 0.3);
    self.numberLabel.backgroundColor = [UIColor blueColor];

    
    
    
    
    
    
}

-(void)setCellModel:(Contact *)cellModel {
    
    if (_cellModel != cellModel) {
        [_cellModel release];
        _cellModel = [cellModel retain];
        
    }
    
    _addressBookImageView.image = [UIImage imageNamed:cellModel.header];
    _nameLabel.text = cellModel.name;
    _numberLabel.text = cellModel.number;
    
    
}








@end
